package cn.img;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;

import javax.imageio.ImageIO;
import java.io.File;

public class Qr2 {
    public static void main(String[] args)  {
        try{
            var img = ImageIO.read(new File("qr.png"));
            var src = new BufferedImageLuminanceSource(img);
            var binarizer = new HybridBinarizer(src);
            var binaryBitmap = new BinaryBitmap(binarizer);
            var result = new QRCodeReader().decode(binaryBitmap);
            System.out.println(result.getText()); //
        }catch(Exception e){
            System.out.println("没有二维码");
        }

    }
}
